package com.GameComponent;

import com.Core.GameEngine;
import com.Triocean.R;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;

public class BackgroundMusic extends Service
{	private MediaPlayer player;
	
	@Override
	public IBinder onBind(Intent arg0)
	{	return null;
	}
	public IBinder onUnBind(Intent arg0)
	{	return null;
	}
	@Override
	public void onCreate()
	{	super.onCreate();
	}
	@Override
	public int onStartCommand(Intent intent, int flags, int startId)
	{	try
		{	setMusicOptions(this, GameEngine.MUSIC_LOOP, GameEngine.R_VOLUME, GameEngine.L_VOLUME, R.raw.titlesong);
			player.start();
		}
		catch (Exception e)
		{	player.stop();
		}
		return 1;
	}
	public void onStart(Intent intent, int startId)
	{}
	public void onStop()
	{}
	public void onPause()
	{}
	@Override
	public void onDestroy()
	{	player.stop();
		player.release();
	}
	@Override
	public void onLowMemory()
	{	player.stop();
	}
	//Subordinate funcs
	public void setMusicOptions(Context context, boolean isLooped, int rVolume, int lVolume, int soundFile)
	{	player=MediaPlayer.create(context, soundFile);
		player.setLooping(isLooped);
		player.setVolume(lVolume, rVolume);
	}
}
